package 搜索页条目;

import Moudle.OutItem;
import MyException.VerificationCodeAppearsException;
import Utils.HttpConnect;
import Utils.Tools;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import MyException.InvalidCookieException;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

    //static final String COOKIE = "UM_distinctid=17a5ace72227fd-0c0a4897bc7715-6373267-1fa400-17a5ace7223db0; Ecp_ClientId=2210630105701723977; cnkiUserKey=29663003-9bec-a0bc-6d89-eb7f3593ecb7; Ecp_ClientIp=114.86.164.175; RsPerPage=50; amid=2b2b5d4d-00da-4f96-a43b-bfb4e1a00341; Ecp_IpLoginFail=210809116.234.209.223; ASP.NET_SessionId=uy4ccbvjgycil0av5txrrpw5; SID_epub=epub120102; _pk_ref=%5B%22%22%2C%22%22%2C1628567581%2C%22https%3A%2F%2Fjrjg.cbpt.cnki.net%2F%22%5D; _pk_ses=*; _pk_id=e70b55ec-f305-4710-982f-c6e2b6815a7a.1625021869.18.1628567966.1628567581.";

    static final String START_DATE = "2005-09-22";
    static final String END_DATE = "2021-07-31";

    static final int REQUEST_DELAY = 0;



    static Map<String, String> headersMap = new HashMap<>();
    static {
        //headersMap.put("Cookie", COOKIE);
        headersMap.put("uniplatform", "BSDZQK");
        headersMap.put("Authorization", "Ecp_ClientId=2210630105701723977; RsPerPage=50; amid=2b2b5d4d-00da-4f96-a43b-bfb4e1a00341; SID_epub=epub120103; _pk_ref=%5B%22%22%2C%22%22%2C1629100367%2C%22https%3A%2F%2Fnavi.cnki.net%2F%22%5D; _pk_ses=*; ASPSESSIONIDCSQCDACR=MNFDFAMAMECJAFOKCBEBAHOJ; Ecp_ClientIp=116.234.209.223; Ecp_IpLoginFail=210816116.234.209.223; cnkiUserKey=27004975-97ca-8ae7-7045-d7018dec50e0; _pk_id=e70b55ec-f305-4710-982f-c6e2b6815a7a.1625021869.25.1629105956.1629100367.; ASP.NET_SessionId=cgoanhofwpaggjes3fmtwcls");
        headersMap.put("Content-Type", "application/x-www-form-urlencoded");
    }

    public static void main(String[] args) throws InvalidCookieException, VerificationCodeAppearsException, IOException, InterruptedException {
        String url = "https://tnei.cnki.net/search-api/v1/criteria/query";

        Map<String, String> dataMap = new HashMap<>();
        for (int i = 1; i < 100; i++) {
            Thread.sleep(2000);
            dataMap.put("q", "{\"resource\":\"DISSERTATION\",\"product\":\"CMFD\",\"q\":{\"userScope\":{\"title\":\"\",\"logic\":0,\"items\":[],\"childItems\":[]}},\"extend\":1,\"start\":"+i+",\"size\":20,\"type\":\"0\",\"sort\":\"PXML\",\"sequence\":\"ASC\"}");
            System.out.println(HttpConnect.HttpPost_OkHttp(url, headersMap, dataMap));
        }

    }


}
